package en.edu.zucc.pb.loginapplication.activity;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
//import android.widget.Toolbar;

import com.facebook.stetho.common.LogUtil;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import en.edu.zucc.pb.loginapplication.MainActivity;
import en.edu.zucc.pb.loginapplication.R;
import en.edu.zucc.pb.loginapplication.adapter.BookkeepingAdapter;
import en.edu.zucc.pb.loginapplication.layout.KeyBoardLinearLayout;
import en.edu.zucc.pb.loginapplication.model.Bookkeeping;
import en.edu.zucc.pb.loginapplication.util.ResUtil;


public class BookkeepingActivity extends AppCompatActivity implements
        View.OnClickListener, NavigationView.OnNavigationItemSelectedListener {
    private static final String TAG = "BookkeepingActivity";

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
//        这个是在右上角的吗
//        onCreateOptionsMenu 左上角
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.keyboard_linearlayout);
//        setContentView(R.layout.home_activity);
//        setContentView(R.layout.keyboard_linearlayout_all);
        setContentView(R.layout.activity_bookkeeping);
        Log.e("tag", "finished");
//        keyBoardLinearLayout = (KeyBoardLinearLayout) findViewById(R.id.kbll_keyboard);
//        keyBoardLinearLayout.setKeyBoartTouchListener(this);

//————————————————
//        版权声明：本文为CSDN博主「qq_36968707_白云」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
//        原文链接：https://blog.csdn.net/qq_36968707/article/details/81163156

//        btn_back_to_login = findViewById(R.id.btn_back_to_login);
//        btn_back_to_login.setOnClickListener(new Button.OnClickListener() {
//            public void onClick(View v) { //使用匿名的Button实例
//
//                //抽象接口的内部方法的实现
//                Intent intent = new Intent(HomeActivity.this, MainActivity.class);
//                startActivity(intent);
//            }
//        });
//
//        tv_keyboard_ok = findViewById(R.id.tv_keyboard_ok);
//        tv_keyboard_ok.setOnClickListener(new View.OnClickListener() {
//            public void onClick(View v) {
////                callPhone();
////                doStartDial(HomeActivity.this);
//                doStartDial(tv_keyboard_ok);
//            }
//        });

//        bindGridKeyboard();

//        tv_dial_str = findViewById(R.id.tv_dial_str);
//        btn1 = findViewById(R.id.btn1);
//        btn1.setOnClickListener(new View.OnClickListener() {
//            public void onClick(View v) {
//                dialStr += btn1.getText();
//                tv_dial_str.setText(dialStr);
//            }
//        });
////        R.id. 可以字符串 表示
////        https://blog.csdn.net/jimbo_lee/article/details/23597083
//        String packageName = getPackageName();
//        Resources resources=getResources();
//        for (int i = 0; i < dialBtns.length; i++) {
////            Resources resources=getResources();
//            String btnIdStr = "btn"+(i+1);
////            int resID = resources.getIdentifier(btnIdStr, "drawable", getPackageName());
//            int resID = ResUtil.getResID(resources, btnIdStr, packageName);
//            Log.i(TAG, "image to show: "+btnIdStr + " id="+resID);
//
//            dialBtns[i] = findViewById(resID);
////            Button btn=dialBtns[i];
//            dialBtns[i].setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
////                    dialStr +=  getText();
//                    dialStr +=  ((Button)v).getText();
//                    tv_dial_str.setText(dialStr);
//                }
//
////                public void onClick(Button v) {
//////                    dialStr +=  this.getText();
//////                    HomeActivity.this.btn.getText();
////                    dialStr +=  getText();
////                    dialStr +=  v.getText();
////                    tv_dial_str.setText(dialStr);
////                }
//            });
//        }
//
//        btn_dial = findViewById(R.id.btn_dial);
//        btn_dial.setOnClickListener(new View.OnClickListener() {
//            public void onClick(View v) {
////                callPhone();
////                doStartDial(HomeActivity.this);
//                doStartDial(btn_dial, dialStr);
//            }
//        });

    ListView listView = findViewById(R.id.listview);
        List<Bookkeeping> bookkeepings=new ArrayList<>();
//        String title, Date date, Double money, int icon) {
        bookkeepings.add(new Bookkeeping( "工作收入",new Date(), 2700.0,R.drawable.ic_launcher_background));
        bookkeepings.add(new Bookkeeping( "工作收入",new Date(), 2700.0,R.drawable.ic_launcher_background));
        bookkeepings.add(new Bookkeeping( "工作收入",new Date(), 2700.0,R.drawable.ic_launcher_background));
        bookkeepings.add(new Bookkeeping("工作收入",new Date(), 2700.0,R.drawable.ic_launcher_background));

        BookkeepingAdapter bookkeepingAdapter = new BookkeepingAdapter(bookkeepings,this);
        listView.setAdapter(bookkeepingAdapter);
//        bindLinearlayoutAll();

         drawerLayout = findViewById(R.id.DrawerLayout);

//        findViewById(R.id.btn_expand).setOnClickListener(this);
//        findViewById(R.id.btn_back_to_login).setOnClickListener(this);
//        setOnClickListenerBtns();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
//        为什么没有反应呢

//        mTextView = (TextView) findViewById(R.id.textView);

        Toolbar toolbar = findViewById(R.id.toolbar);
//        toolbar.setTitle("Step5");
        setSupportActionBar(toolbar);
//        这个版本还不对了

        //配置抽屉布局
//        这里设置了 就有三横的东西可以打开侧边栏了
//        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawerLayout.addDrawerListener(toggle);
        toggle.syncState();

//        View headerView = navigationView.inflateHeaderView(R.layout.nav_header);
        View headerView = navigationView.getHeaderView(0);
        ImageView login = (ImageView) headerView.findViewById(R.id.ivAvatar);

        login.setOnClickListener(this);
    }

    void setOnClickListenerBtns(){
                findViewById(R.id.btn_expand).setOnClickListener(this);
        findViewById(R.id.btn_back_to_login).setOnClickListener(this);
        findViewById(R.id.btn_setting).setOnClickListener(this);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        int id = item.getItemId();
//        好像没有什么反应啊
//        onNavigationItemSelected 没用
        String string = null;
        Log.i(TAG,"onNavigationItemSelected");
        switch (id){

            case R.id.nav_about:
                string = "关于";
                break;

            case R.id.nav_night:
                string = "夜间模式";
                break;

            case R.id.nav_setting:
                string= "设置";
                break;
            case R.id.nav_suggestion:
                string = "意见反馈";
                break;
            case R.id.nav_theme:
                string = "主题风格";
                break;
        }
        if (!TextUtils.isEmpty(string)){
            Toast.makeText(this,"你点击了"+string,Toast.LENGTH_SHORT).show();
            Log.i(TAG,"你点击了"+string);
        }
//            mTextView.setText("你点击了"+string);
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

    DrawerLayout drawerLayout;



    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_expand:

//                drawerLayout.openDrawer(findViewById(R.id.expanded_menu));
                drawerLayout.openDrawer(findViewById(R.id.nav_view));
                break;
            case R.id.btn_back_to_login:
                Intent intent = new Intent(this, MainActivity.class);
                startActivity(intent);
                break;
            case R.id.btn_setting:
//                这个点击是没有反应的
                Toast.makeText(this,"点击了设置",Toast.LENGTH_SHORT).show();
//                LogUtil.i(TAG,"点击了设置");
                Log.i(TAG,"点击了设置");
                break;
            case R.id.ivAvatar:
                 intent = new Intent(this, MainActivity.class);
                startActivity(intent);
                break;


        }
    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }


//————————————————
//    版权声明：本文为CSDN博主「qq_36968707_白云」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
//    原文链接：https://blog.csdn.net/qq_36968707/article/details/81163156    }
}
